﻿using IdentityServer4;
using IdentityServer4.Models;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;

namespace JTTD.Model
{
    public class TokenConfig
    {
        /// <summary>
        /// 添加对OpenID Connect的支持
        /// </summary>
        /// <returns></returns>
        public static IEnumerable<IdentityResource> GetIdentityResources()
        {
            return new List<IdentityResource>
            {
                new IdentityResources.OpenId(), //必须要添加，否则报无效的scope错误
                new IdentityResources.Profile()
            };
        }
        /// <summary>
        /// 定义系统中的API资源
        /// </summary>
        /// <returns></returns>
        public static IEnumerable<ApiResource> GetApiResources()
        {
            return new List<ApiResource>
            {
                new ApiResource("jttdApi", "jttdApi")
            };
        }

        /// <summary>
        /// 客户端访问资源
        /// </summary>
        /// <returns></returns>
        public static IEnumerable<Client> GetClients()
        {
            // 客户端信息
            return new List<Client>
            {
             //自定义接口登录的客户端
             new Client
                {
                    //客户端ID名称
                    ClientId = "jttdClient",
                    //客户端访问方式：密码验证
                    AllowedGrantTypes = GrantTypes.ResourceOwnerPassword,
                    //过期时间
                    AccessTokenLifetime = 24 * 3600,
                    //用于认证的密码加密方式
                    ClientSecrets =
                    {
                        new Secret("jttdSecret".Sha256())
                    },
                    //客户端有权访问的范围
                    AllowedScopes = { "jttdApi",
                        IdentityServerConstants.StandardScopes.OpenId, //必须要添加，否则报403 forbidden错误
                        IdentityServerConstants.StandardScopes.Profile
                     }
                }
            };
        }
    }
}
